<template>
  <div class="regist">
    <mt-header>
      <mt-button icon="back" slot="back"></mt-button>
    </mt-header>
    <div class="pageBody">
      <div class="inputRow">
        <mt-field
          placeholder="手机号"
          type="tel"
          :attr="{ maxlength: 11 }"
          v-model="mobile"
        ></mt-field>
      </div>

      <div class="inputRow">
        <mt-field placeholder="验证码" type="text" v-model="code"></mt-field>
        <button class="btnGetCode" v-if="show" @click="getCode">
          获取验证码
        </button>
        <button class="btnGetCode btnAgain" v-if="!show" disabled>
          重新发送{{ times }}s
        </button>
      </div>

      <div class="inputRow">
        <mt-field
          placeholder="密码"
          type="password"
          v-model="password"
        ></mt-field>
      </div>

      <mt-button type="primary" class="btnSubmit" @click="submit"
        >下一步</mt-button
      >
    </div>
  </div>
</template>


<script>
import MtHeader from "@/components/MtHeader.vue";
export default {
  components: { MtHeader },
  data() {
    return {
      times: 59,
      show: true,
      mobile: "",
      code: "",
      password: "",
    };
  },
  methods: {
    getCode() {
      this.show = false;
      this.timer = setInterval(() => {
        this.times--;
        if (this.times <= 0) {
          this.show = true;
          this.times = 59;
          clearInterval(this.timer);
        }
      }, 1000);
    },

    //提交
    submit() {
      let mobile = this.mobile;
      let code = this.code;
      let password = this.password;
      if (mobile && code && password) {
        this.$router.push("/registInfo");
      } else {
        this.$toast({
          message: "请填写完信息",
          duration: 1000,
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.regist {
  height: 100%;
  .pageBody {
    border-top: 1px solid Gainsboro;
    box-sizing: border-box;
    padding: 10px;
    background: white;
    height: calc(100% - 40px);
  }
}

.inputRow {
  border-bottom: 1px solid #eee;
  align-items: center;
  font-size: 1rem;
  display: flex;
  margin-bottom: 10px;
  input {
    min-width: 40px;
    height: 44px;
    flex: 1;
    border: none;
    background: none;
    line-height: 34px;
    padding: 0;
    outline: none;
    font-size: 1.2rem;
  }

  .btnGetCode {
    background: none;
    border: none;
    height: 40px;
    font-size: 1rem;
    width: 200px;
  }
}

.btnSubmit {
  width: calc(100%);
  margin-top: 70px;
}
</style>